<?php
namespace Yzadmin\Controller;
use Think\Controller;
class IndexController extends CkController
{
   //后台首页
   public function index()
   { 
     $data['user_top10']=M("user")->field("id,user_tel,nickname,balance+paid as zonger")->limit(10)->order("zonger desc")->select();
     $data['tongji'] = M("time_jifei_ip")->order("id desc")->limit(10)->select();
     $this->assign($data);
     $this->display();
   }    
   
   //密码修改
   public function password()
   { 
     $data['title']="密码修改";
     $this->assign($data);
     $this->display();
   }
   
   //密码修改处理
   public function password_do()
   {
     $data= I('post.');
     if(empty($data['password']) || empty($data['password2'])){
       $this->error("请输入密码!");
     }
     if($data['password']!==$data['password2'])
     {
        $this->error("2次密码不一致");
     }
     $uid= cookie('admin_id');
     if(M("admin")->where(array("id"=>$uid))->setField('password',md5($data['password']))!==false){
        $this->success("密码修改成功.请重新登陆");
        cookie("admin_username",null);
     }else{
         $this->success("密码修改失败.");
     }
   }
    
    //清理缓存
    public function clear() {
        header("Content-Type:text/html; charset=utf-8");//不然返回中文乱码
        //清除缓存
        clearCache();
        $this->success('清楚成功');  
    }
   

}